﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Entity;

namespace Web.frontpage
{
    public partial class InnerContest : System.Web.UI.Page
    {
        private ContestService contestService = new ContestService();
        private CompetitionService competitionService = new CompetitionService();
        private ParticipantService participantService = new ParticipantService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                IList<BoContests> contests = contestService.getInnerContests();
                IList<BoContests> contest3 = new List<BoContests>();
                for (int i = 0; i < 3 && i < contests.Count; i++)
                {
                    contest3.Add(contests[i]);
                }
                Rp_Contest.DataSource = contest3;
                Rp_Contest.DataBind();
                Rp_ConItem.DataSource = contestService.GetProceduresByTime(DateTime.Parse("1900/01/01"));
                Rp_ConItem.DataBind();

                Rp_Com.DataSource = competitionService.getInnerCompetitions();
                Rp_Com.DataBind();

                RpAward.DataSource = participantService.getAllInnerAwardsPar();
                RpAward.DataBind();
            }
        }
        /// <summary>
        /// 登录事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void login(object sender, EventArgs e)
        {
            string usm = username.Value;
            string pwd = password.Value;
            if (!string.IsNullOrEmpty(usm) || !string.IsNullOrEmpty(pwd))
            {
                if (rb_student.Checked) //即登录为学生
                {
                    BLL.StudentService students = new BLL.StudentService();
                    BoStudents model = new BoStudents();
                    model.STU_USERNAME = usm;
                    model.STU_PASSWORD = pwd;
                    BoStudents resultModel = students.CheckStudent(model);
                    if (resultModel != null)
                    {
                        Session["studentId"] = resultModel.STU_ID;
                        Session["studentName"] = resultModel.STU_NAME;
                        Response.Redirect("SignUp/SUIndex.aspx");
                    }
                    else
                    {
                        Response.Write("<script>alert(\"用户名或者密码错误\")</script>");
                    }
                }
                else if (rb_manager.Checked)//即管理员或者老师
                {
                    Response.Write("<script>alert(\"暂未开放\")</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('不允许有空项')</script>");
                return;
            }
        }
    }
}